﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using ISS.IR.RRNMS.Library.DataAccess;

namespace ISS.IR.RRNMS.Library.BusinessLogic
{
    public class Calendar
    {
         

        #region Public Properties

        public Item Account { get; set; }
        public Item User { get; set; }
        public Item Room { get; set; }
        public Slot Slot { get; set; }
        public DateTime Date { get; set; }

        
        
        #endregion

        #region constructor

        public Calendar() { }

        #endregion

        #region private Method

        #endregion

        #region public method
        public  List<Calendar> SelectCalendarEntitesByDateAndRoom(DateTime Date,int RoomId) {
            try { return Main.SelectCalendarEntitesByDateAndRoom(Date, RoomId); }
            catch (Exception e) { return null; }
        }
        public  List<Item> SelectItemsByCategory(int CategoryId) {
            try
            {
                DataTable dtMaster = Main.SelectItemsByCategory(CategoryId);

                List<Item> liRoom = new List<Item>();
                if (dtMaster != null)
                {
                    for (int i = 0; i < dtMaster.Rows.Count; i++)
                    {

                        Item temp = new Item();
                        temp.Id = Convert.ToInt32(dtMaster.Rows[i]["Id"]);
                        temp.Value = Convert.ToString(dtMaster.Rows[i]["Value"]);
                        liRoom.Add(temp);
                    }
                }
                return liRoom;
            }
            catch (Exception e) { return null; }
        }
        public List<Item> SelectListOfAllAccounts() { try { return Main.SelectListOfAllAccounts(); } catch (Exception e) { return null; } }
        public List<Item> SelectListOfAllUsers() { try { return Main.SelectListOfAllUsers(); } catch (Exception e) { return null; } }
        public  List<Item> SelectListOfAllSlots()
        {
            try
            {
                List<Slot> slots = Main.SelectListOfAllSlots();
                List<Item> item = new List<Item>();
                for (int i = 0; i < slots.Count; i++)
                {
                    //slots.Add(new Library.Slot());
                    Item temp = new Item();
                    temp.GUID = Guid.Parse(Convert.ToString(slots[i].SlotId));
                    temp.Value = slots[i].ToString();
                    item.Add(temp);
                }
                Item x = new Item();
                x.Id = 0;
                x.Value = "";
                item.Insert(0, x);
                return item;
            }catch(Exception e)
            {return null;}

        
        }
        public List<Item> SelectListOfAllRooms(int CategoryId) 
        {
            try
            {
                DataTable dtMaster = Main.SelectItemsByCategory(CategoryId);

                List<Item> liRoom = new List<Item>();
                if (dtMaster != null)
                {
                    for (int i = 0; i < dtMaster.Rows.Count; i++)
                    {

                        Item temp = new Item();
                        temp.Id = Convert.ToInt32(dtMaster.Rows[i]["Id"]);
                        temp.Value = Convert.ToString(dtMaster.Rows[i]["Value"]);
                        liRoom.Add(temp);
                    }
                }
                Item x = new Item();
                x.Id = 0;
                x.Value = "";
               liRoom.Insert(0, x);

               return liRoom;

            }
            catch (Exception e)
            { return null; }
        
        }
        public int InsertNewAppointmant(Calendar calender)
        {
            try
            {
                int rowindex = Main.InsertNewAppointmant(calender);
                return rowindex;
            }
    catch(Exception e){return 0;}
        }

        public List<Guid> SelectSlotsToCheck(Calendar calender)
        {
          try { return Main.SelectSlotsToCheck(calender); }
            catch (Exception e) { return null; }
        }

        public bool SelectSlotsToCheckBeforeInsert(Calendar calender)
        {
            try { return Main.SelectSlotsToCheckBeforeInsert(calender); }
            catch (Exception e) { return false; }
        }

        public int DeleteAppointmant(Calendar calender)
        {
            try { return  Main.DeleteAppointmant(calender); }
            catch (Exception e) { return 0; }
        }
        public Guid CalendarSaveAccount(string firstname, string secondname, string thirdname, string fourthname, string UNHCR, string Telephone)
        {
            try { return Main.CalendarSaveAccount(firstname, secondname, thirdname, fourthname, UNHCR, Telephone); }
            catch (Exception) { return Guid.Parse(""); }
        }
  #endregion

        #region override


    

        #endregion

    }
}
